package com.jinzhi.common.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.domain.LogDO;
import com.jinzhi.common.service.LogService;
import com.jinzhi.common.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * <pre>
 * 日志
 * </pre>
 * 
 * <small> 2018年3月23日 | Aron</small>
 */
@RequestMapping("/common/log")
@Controller
public class LogController extends BaseController {
    @Autowired
    LogService logService;
    String prefix = "";
    
    @GetMapping()
    @RequiresPermissions("jzweb:log:list")
    String log() {
        return  "common/log/log";
    }
    @GetMapping("/orderFromLog")
    @RequiresPermissions("jzweb:orderFromLog:list")
    String olderForm() {
        return  "common/log/orderFromLog";
    }

    /**
     * 分页查询列表
     * @param logDTO
     * @return
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions("jzweb:log:list")
    public Result<Page<LogDO>> list(@RequestBody LogDO logDTO) {
        return Result.ok(logService.getLogListPage(logDTO));
    }

    /**
     * 导出日志
     * @param response
     * @param logDTO
     */
    @Log(value = "导出系统日志",sysModule = 12,operationType = 4)
    @ResponseBody
    @GetMapping("/download")
    public void downloadImportTemplate(HttpServletResponse response, LogDO logDTO) {
        logService.downloadImportTemplate(response, logDTO);
    }
    
    @Log(value = "删除系统日志",sysModule = 12,operationType = 2)
    @ResponseBody
    @PostMapping("/remove")
    Result<String> remove(Long id) {
        logService.deleteById(id);
        return success();
    }
    
    @Log(value = "批量删除系统日志",sysModule = 12,operationType = 2)
    @ResponseBody
    @PostMapping("/batchRemove")
    Result<String> batchRemove(@RequestParam("ids[]") Long[] ids) {
        boolean update = logService.deleteBatchIds(Arrays.asList(ids));
        return update?Result.ok():Result.fail();
    }
}
